package demo.virtuemart.cart;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import demo.virtuemart.Util.TestUtil;

public class CheckTotal extends TestSuiteBase{
	String [] runmode=null;
	static int count = -1;
	static boolean pass=false;
	static boolean fail=false;
	static boolean skip=false;
	
	@BeforeTest
	public void checkTestSkip() throws Throwable 
	{
		if(!TestUtil.isTestCaseRunnable(suite_cart_xls, this.getClass().getSimpleName()))
		{
			logs.debug("Log Message---- Skipping the test case" +this.getClass().getSimpleName()+"as the run mode set to no");
			skip=true;
			throw new SkipException("Skipping the test case" +this.getClass().getSimpleName()+"as the run mode set to no");
		}
		runmode = TestUtil.getDataSetRunModes(suite_cart_xls, this.getClass().getSimpleName());
	}
	
	@Test
	public void checkTotal()
	{
		count = count+1;
		if(!runmode[count].equalsIgnoreCase("Y"))
		{	
		throw new SkipException("Run mode for test set data set " +count + "is set to no");
		}
		logs.debug("Executing Check Total");
		
		/*WebElement shoppingcart = driver.findElement(By.xpath("//*[@id='item-109']/a/span"));
		Actions action = new Actions(driver);
		action.moveToElement(shoppingcart).click().build().perform();*/
		
		
		getObject("show_cart_link").click();
		int noofmobiles= sessionData.size();
		for(int i=0;i<noofmobiles;i++)
		{
			sessionData.get("mobile_"+i);
		}
	}
	
	
	
	@AfterMethod
	public void report() throws Throwable
	{
		if(skip)
		{
			TestUtil.reportDataSetResult(suite_cart_xls, this.getClass().getSimpleName(), count+2, "Skip");
		}
		else if(fail)
		{
			  TestUtil.reportDataSetResult(suite_cart_xls, this.getClass().getSimpleName(), count+2, "Fail");
		}
		else
		{
			  TestUtil.reportDataSetResult(suite_cart_xls, this.getClass().getSimpleName(), count+2, "Pass");
		}
		skip=false;
		fail=false;
		pass=false;
	}
	@AfterTest
	public void reportTestResult() throws Throwable
	{
		if(pass)
			TestUtil.reportDataSetResult(suite_cart_xls, "Test Cases", TestUtil.getRowNum(suite_cart_xls,this.getClass().getSimpleName())+1, "Pass");
			
		else
			TestUtil.reportDataSetResult(suite_cart_xls, "Test Cases", TestUtil.getRowNum(suite_cart_xls, this.getClass().getSimpleName())+1, "Fail");
	}
}
